﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.DataAccess;
using System.Data;
using University.Workshop.Model;
using System.Globalization;

namespace University.Workshop.Business
{
    public static class ProductManager
    {
        public static int LoadNBuyProduct()
        {
            DataSet dataset= ProductDataAccess.LoadNBuyProduct();
            int nProduct = int.Parse(dataset.Tables[0].Rows[0][0].ToString(),CultureInfo.InvariantCulture);            
            return nProduct;
        }

        public static bool NewProductRegister(Product product,ProductBuy buy)
        {
            return ProductDataAccess.ProductRegister(product,buy);
        }

        public static DataTable LoadDataGridBuy()
        {
            return ProductDataAccess.LoadDataGridBuy();
        }

        public static DataTable LoadProduct(string product)
        {
            return ProductDataAccess.LoadProduct(product);
        }
        public static DataTable LoadNameProduct(string product)
        {
            return ProductDataAccess.LoadNameProduct(product);
        }
        public static DataTable LoadDataGridViewSearchBuyProduct(string searchProduct)
        {
            return ProductDataAccess.LoadDataGridViewSearchBuyProduct(searchProduct);
        }

        public static string TotalPriceBuy(string unitPrice, string totalPrice)
        {
            if (ValidateFields.ValidateNumberFields())
            {
                float total = float.Parse(unitPrice) * float.Parse(totalPrice);
                return Convert.ToString(total);
            }
            else 
            {
                return null;
            }
        }

        public static DataTable LoadDataGridProduct(string idProduct)
        {
            return ProductDataAccess.LoadDataGridProduct(idProduct);
        }

        public static bool ModifyProductRegister(Product product, ProductBuy buy)
        {
            return ProductDataAccess.ProductModify(product, buy);
        }
    }
}
